<?php
#=================================================================================================================
#=================================================================================================================
#	Define all possible options in drop-down menu
#=================================================================================================================
#=================================================================================================================

//include "javascript".DIRECTORY_SEPARATOR."serverside.php";

 $countiesForForm = array();
 $allCounties = getCounties();
 $i = 1;
 
 foreach ($allCounties as $county){
	$countiesForForm["opt".$i] = $county ;
	$i++;
 }

 if( isset($_GET['edit_furnizor']) or isset($_POST['edit_furnizor']) or isset($_GET['view_furnizor']) or  isset($_POST['view_furnizor']) )
 {
	 $query_furnizori = mysqli_query($dbc, "SELECT `CUI_CF`, `cod_judet`, `numar_decizie_autorizare`, `data_decizie_autorizare`, `nume`, `regiune`, `judet`, `localitate`, `localizare`, `strada`, `nr_strada`, `bloc`, `scara`, `etaj`, `apartament`, `telefon`, `fax`, `email`, `website`, `forma_organizare`, `forma_proprietate`, `smac`, `email_user_comisie` FROM `furnizor` WHERE `CUI_CF`='$var_cui_furnizor'");
	 
	if( $query_furnizori)
	{
		if($results_furnizori = mysqli_fetch_assoc($query_furnizori))
		{
	 
			$form_for_table = array(
			#----------------------------------------------------------------------
			#						Tabel										  |
			#----------------------------------------------------------------------
				
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Nume furnizor',
					  'post_name' 			 => 'nume_furnizor',
					  'current_value'		 => $results_furnizori['nume'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'CUI/CF',
					  'post_name' 			 => 'CUI_CF',
					  'field_size' 			=> 40,	
					  'max_length' 			=> 10,
					  'current_value'		 => $results_furnizori['CUI_CF'],
					  'validation_function'   => 'validate_cif',
					  'errors' 				=> array(
													'empty_field_or_no_selection_error' => 'Introduceti CUI/CF<br />',
													'no_regex_pattern_found_error' => 'CUI/CF invalid<br />' )),
								
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Numar decizie autorizare',
					  'post_name' 			 => 'numar_decizie_autorizare',
					  'current_value'		 => $results_furnizori['numar_decizie_autorizare'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Data decizie autorizare',
					  'post_name' 			 => 'data_decizie_autorizare',
					  'current_value'		 => $results_furnizori['data_decizie_autorizare'],
					  'placeholder'          => 'AAAA-LL-ZZ',
					  'title'				=> 'An-Luna-Zi',
					  'validation_function'   => 'dateLTEToday',
					  'regex'				=> '/^[1-2][0-9]{3}-(0[1-9]|10|11|12)-(0[1-9]|[1-2][0-9]|3[0-1])$/',
					  'errors' 				=> array(
													'empty_field_or_no_selection_error' => 'Introduceti o data de decizie a autorizatiei<br />',
													'no_regex_pattern_found_error' => 'Introduceti o data valida de decizie a autorizatiei<br />' ),
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
				
				array('field_type' 			=> 'drop_down_list',
					  'field_display_name' 	=> 'Forma organizare',
					  'post_name' 			 => 'forma_organizare',
					  'current_value'		 => $results_furnizori['forma_organizare'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100,
					  'initial_values'  		=> array('opt1' => 'S.R.L.',
													   'opt2' => 'S.A',
													   'opt3' => 'O.N.G',
													   'opt4' => 'Instituție Publică',
													   'opt5' => 'Instituție Publică de Cultură',
													   'opt6' => 'Casă Centrală',
													   'opt7' => 'Societate Cooperativă',
													   'opt8' => 'Cooperativă Agricolă',
													   'opt9' => 'Institut Național de Cercetare/ Dezvoltare',
													   'opt10' => 'Grup de Interes Economic (comerciant/ necomerciant)',
													   'opt11' => 'Grup European de Interes Economic (comerciant/ necomerciant)',
													   'opt12' => 'Societate Europeană',
													   'opt13' => 'Societate Cooperativă Europeană',
													   'opt14' => 'Sucursală',
													   'opt15' => 'Persoană Fizică Autorizată – PFA',
													   'opt16' => 'Asociație ',
													   'opt17' => 'Fundație',
													   'opt18' => 'Companie Națională',
													   'opt19' => 'Societate Națională',
													   'opt20' => 'Regie Autonomă',
													   'opt21' => 'Cooperativă de Credit',
													   'opt22' => 'Filială de fundație',
													   'opt23' => 'Unitate în structura rețelei de învățământ'
													  
													   )
						),
					 
				array('field_type' 			=> 'drop_down_list',
					  'field_display_name' 	=> 'Forma proprietate',
					  'post_name' 			 => 'forma_proprietate',
					  'current_value'		 => $results_furnizori['forma_proprietate'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100,
					  'initial_values'  		=> array('opt1' => 'Publica',
													   'opt2' => 'Privata',
													   'opt3' => 'Mixta'
													   )
						),
					  
				array('field_type' 			=> 'drop_down_list',
					  'field_display_name' 	=> 'Sistem de management al calitatii',
					  'post_name' 			 => 'smac',
					  'current_value'		 => $results_furnizori['smac'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100,
					  'initial_values'  		=> array('opt1' => 'Da',
													   'opt2' => 'Nu'
													   )
					  ),

				array('field_type' 			=> 'drop_down_list',
					  'field_display_name' 	=> 'Judet',
					  'post_name' 			 => 'judet',
					  'id'					=> 'judet_furnizor',
					  'current_value'		 => $results_furnizori['judet'],
					  'initial_values'		=> $countiesForForm,
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'drop_down_list',
					  'field_display_name' 	=> 'Localizare',
					  'post_name' 			 => 'localizare',
					  'current_value'		 => $results_furnizori['localizare'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100,
					  'initial_values'  		=> array('opt1' => 'Urban',
													   'opt2' => 'Rural')
						),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Localitate',
					  'id'					=> 'localitate_furnizor',
					  'post_name' 			 => 'localitate',
					  'current_value'		 => $results_furnizori['localitate'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Strada',
					  'post_name' 			 => 'strada',
					  'current_value'		 => $results_furnizori['strada'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Numar strada',
					  'post_name' 			 => 'nr_strada',
					  'current_value'		 => $results_furnizori['nr_strada'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Bloc',
					  'post_name' 			 => 'bloc',
					  'current_value'		 => $results_furnizori['bloc'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100), 
					 
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Scara',
					  'post_name' 			 => 'scara',
					  'current_value'		 => $results_furnizori['scara'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Etaj',
					  'post_name' 			 => 'etaj',
					  'current_value'		 => $results_furnizori['etaj'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Apartament',
					  'post_name' 			 => 'apartament',
					  'current_value'		 => $results_furnizori['apartament'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Telefon',
					  'post_name' 			 => 'telefon',
					  'current_value'		 => $results_furnizori['telefon'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					  
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Fax',
					  'post_name' 			 => 'fax',
					  'current_value'		 => $results_furnizori['fax'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					 
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Email',
					  'post_name' 			 => 'email',
					  'current_value'		 => $results_furnizori['email'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100),
					
				array('field_type' 			=> 'text',
					  'field_display_name' 	=> 'Site',
					  'post_name' 			 => 'site',
					  'current_value'		 => $results_furnizori['website'],
					  'field_size' 			=> 40,
					  'max_length' 			=> 100)
			);	
		}
	}
	 
 }
 else
 {


	
	$form_for_table = array(
	#----------------------------------------------------------------------
	#						Tabel										  |
	#----------------------------------------------------------------------
		
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Nume furnizor',
			  'post_name' 			 => 'nume_furnizor',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'CUI/CF',
			  'post_name' 			 => 'CUI_CF',
			  'id'					=> 'CUI_CF',
			  'placeholder'			=> 'CUI sau CF',
			  'title'				=> 'Cod Unic de Identificare sau Cod Fiscal',
			  'field_size' 			=> 40,	
			  'max_length' 			=> 10,
			  'validation_function'   => 'validate_cif',
			  'errors' 				=> array(
											'empty_field_or_no_selection_error' => 'Introduceti CUI/CF<br />',
											'no_regex_pattern_found_error' => 'CUI invalid<br />' )),
																			
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Numar decizie autorizare',
			  'post_name' 			 => 'numar_decizie_autorizare',
			  'regex'				 => '/^[\d]{1,11}$/',
			  'placeholder'			=> 'Ex. 1000',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Data decizie autorizare',
			  'post_name' 			 => 'data_decizie_autorizare',
			  'placeholder'          => 'AAAA-LL-ZZ',
			  'title'				=> 'An-Luna-Zi',
			  'validation_function'   => 'dateLTEToday',
			  'regex'				=> '/^[1-2][0-9]{3}-(0[1-9]|10|11|12)-(0[1-9]|[1-2][0-9]|3[0-1])$/',
			  'errors' 				=> array(
											'empty_field_or_no_selection_error' => 'Introduceti o data de decizie a autorizatiei<br />',
											'no_regex_pattern_found_error' => 'Introduceti o data valida de decizie a autorizatiei<br />' ),
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
		
		array('field_type' 			=> 'drop_down_list',
			  'field_display_name' 	=> 'Forma organizare',
			  'post_name' 			 => 'forma_organizare',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100,
			  'current_value'		 => 'opt1',
			  'initial_values'  		=> array(	   'opt1' => 'S.R.L.',
													   'opt2' => 'S.A',
													   'opt3' => 'O.N.G',
													   'opt4' => 'Instituție Publică',
													   'opt5' => 'Instituție Publică de Cultură',
													   'opt6' => 'Casă Centrală',
													   'opt7' => 'Societate Cooperativă',
													   'opt8' => 'Cooperativă Agricolă',
													   'opt9' => 'Institut Național de Cercetare/ Dezvoltare',
													   'opt10' => 'Grup de Interes Economic (comerciant/ necomerciant)',
													   'opt11' => 'Grup European de Interes Economic (comerciant/ necomerciant)',
													   'opt12' => 'Societate Europeană',
													   'opt13' => 'Societate Cooperativă Europeană',
													   'opt14' => 'Sucursală',
													   'opt15' => 'Persoană Fizică Autorizată – PFA',
													   'opt16' => 'Asociație ',
													   'opt17' => 'Fundație',
													   'opt18' => 'Companie Națională',
													   'opt19' => 'Societate Națională',
													   'opt20' => 'Regie Autonomă',
													   'opt21' => 'Cooperativă de Credit',
													   'opt22' => 'Filială de fundație',
													   'opt23' => 'Unitate în structura rețelei de învățământ'
											  
											   )
				),
			 
		array('field_type' 			=> 'drop_down_list',
			  'field_display_name' 	=> 'Forma proprietate',
			  'post_name' 			 => 'forma_proprietate',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100,
			  'current_value'		 => 'opt1',
			  'initial_values'  		=> array('opt1' => 'Publica',
											   'opt2' => 'Privata',
											   'opt3' => 'Mixta'
											   )
				),
			  
		array('field_type' 			=> 'drop_down_list',
			  'field_display_name' 	=> 'Sistem de management al calitatii',
			  'post_name' 			 => 'smac',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100,
			  'current_value'		 => 'opt1',
			  'initial_values'  		=> array('opt1' => 'Da',
											   'opt2' => 'Nu'
											   )
			  ),
			  
		
		array('field_type' 			=> 'drop_down_list',
			  'field_display_name' 	=> 'Judet', 
			  'placeholder'			=> 'Judetul',
			  'post_name' 			 => 'judet',
			  'field_size' 			=> 40,
			  'id'					=> 'judet_furnizor',
			  'initial_values'		=> $countiesForForm,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'drop_down_list',
			  'field_display_name' 	=> 'Localizare',
			  'post_name' 			 => 'localizare',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100,
			  'current_value'		 => 'lala',
			  'initial_values'  		=> array('opt1' => 'Urban',
											   'opt2' => 'Rural')
				),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Localitate',
			  'post_name' 			 => 'localitate',
			  'placeholder'			=> 'Localitatea',
			  'id'					=> 'localitate_furnizor',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Strada',
			  'post_name' 			 => 'strada',
			  'placeholder' 			 => 'Ex. Iuliu Maniu',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Numar strada',
			  'post_name' 			 => 'nr_strada',
			  'placeholder' 			 => 'Ex. 100',
			  'regex'				 => '/^(-|[\w ]{1,10})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Bloc',
			  'post_name' 			 => 'bloc',
			  'placeholder' 			 => 'Ex. R20',
			  'regex'				 => '/^(-|[\w ]{1,10})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100), 
			 
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Scara',
			  'post_name' 			 => 'scara',
			  'placeholder' 			=> 'Ex. A',
			  'regex'				 => '/^(-|[\w ]{1,5})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Etaj',
			  'post_name' 			 => 'etaj',
			  'placeholder' 			=> 'Ex. 5',
			  'regex'				 => '/^(-|[\d]{1,11})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Apartament',
			  'post_name' 			 => 'apartament',
			  'placeholder' 			=> 'Ex. 15',
			  'regex'				 => '/^(-|[\d]{1,5})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Telefon',
			  'post_name' 			 => 'telefon',
			  'placeholder' 			=> 'Ex. 07xx123456 sau 02xx123456',
			  'regex'				 => '/^(-|((\(\+4\)|\+4))?[-\s]?\(?((01|02|03|04|05|06|07)\d{2})?\)?[-\s]?\d{3}[-\s]?\d{3})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			  
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Fax',
			  'post_name' 			 => 'fax',
			  'placeholder' 			=> 'Ex. 07xx123456 sau 02xx123456 sau 03xx123456',
			  'regex'				 => '/^(-|((\(\+4\)|\+4))?[-\s]?\(?((01|02|03|04|05|06|07)\d{2})?\)?[-\s]?\d{3}[-\s]?\d{3})$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			 
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Email',
			  'post_name' 			 => 'email',
			  'placeholder' 			=> 'Ex. utilizator@domeniu.ro',
			  'regex'				 => '/^(-|[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.[_a-z]{2,4}))$/',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			
		array('field_type' 			=> 'text',
			  'field_display_name' 	=> 'Site',
			  'placeholder' 			=> 'Ex. adresa.domeniu.ro',
			  'post_name' 			 => 'site',
			  'field_size' 			=> 40,
			  'max_length' 			=> 100),
			 
		array('field_type' 			=> 'div',
			  'id' 			 		=> 'dialogCUI_CF',
			  'title'		 		=> 'CUI/CF existent')
	);	
 }
#=================================================================================================================
#	End of drop-down elemnts
#=================================================================================================================

?>